﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting.Messaging;

namespace ServiceController
{
    public delegate DataAccess.DataAccessResult ListHostServiceDelegate(String SubscriptionID, String CertificatePath);
    public partial class ServiceController
    {

        ListHostServiceDelegate _ListHostServiceDelegate;
        public void GetListHostServicesAsync(String SubscriptionID, String CertificatePath, object UserState)
        {
            _ListHostServiceDelegate.BeginInvoke(SubscriptionID, CertificatePath, new AsyncCallback(GetListHostServiceCallback), UserState);
        }

        private void GetListHostServiceCallback(IAsyncResult ar)
        {
            AsyncResult aresult = (AsyncResult)ar;
            DataAccess.DataAccessResult result = _ListHostServiceDelegate.EndInvoke(ar);
            OnGetListHostServiceCompleted(new ServiceControllerEventArgs()
            {
                ListHostService = result.HostServiceList,
                error = result.Error,
                UserState = ar.AsyncState,
                IsOperationSuccessful = result.IsOperationSuccessful,
            });
        }

        private DataAccess.DataAccessResult GetListHostServices(String SubscriptionID, String CertificatePath)
        {
            DataAccess.DataAccessResult result = da.GetListHostServices(SubscriptionID, CertificatePath);
            return result;
        }
    }
}
